home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Resources / UseRes.dpr < prev   
Encoding:
Text File  |  2004-10-22  |  1.9 KB  |  87 lines

  1. program UseRes;
  2.  
  3. uses
  4.   System.Drawing,
  5.   System.Resources,
  6.   System.Collections,
  7.   System.Windows.Forms;
  8.  
  9. type
  10.   { .NET to VCL mapping }
  11.   TForm   = System.Windows.Forms.Form;
  12.   TBitmap = System.Drawing.Bitmap;
  13.   TIcon   = System.Drawing.Icon;
  14.   TCursor = System.Windows.Forms.Cursor;
  15.  
  16. type
  17.   { Application main form }
  18.   [STAThread]
  19.   TMainForm = class(TForm)
  20.   private
  21.     ResTbl: HashTable;
  22.     SplashBitmap: Bitmap;
  23.     procedure InitComponents;
  24.   protected
  25.     procedure PaintHandler(Sender: TObject; pe: PaintEventArgs);
  26.     function LoadResource(resFile: string): HashTable;
  27.   public
  28.     constructor Create(Owner: TObject);
  29.   end;
  30.  
  31. { TMainForm }
  32.  
  33. constructor TMainForm.Create(Owner: TObject);
  34. begin
  35.   inherited Create;
  36.   InitComponents;
  37. end;
  38.  
  39. procedure TMainForm.InitComponents;
  40. begin
  41.   SuspendLayout;
  42.   ResTbl:= LoadResource('MyRes.resources');
  43.  
  44.   Text:= 'Using Resources';
  45.  
  46.   SplashBitmap:= TBitmap(ResTbl['SPLASH']);
  47.   Icon:= TIcon(ResTbl['MAINICON']);
  48.   Cursor:= TCursor(ResTbl['MAINCURSOR']);
  49.  
  50.   AutoScaleBaseSize:= Size.Create(5, 13);
  51.   ClientSize:= Size.Create(750, 500);
  52.   add_Paint(PaintHandler);
  53.   ResumeLayout(False);
  54. end;
  55.  
  56. function TMainForm.LoadResource(resFile: string): HashTable;
  57. var
  58.   rr: ResourceReader;
  59.   resTbl: Hashtable;
  60.   de: IDictionaryEnumerator;
  61. begin
  62.   try
  63.     resTbl:= Hashtable.Create;
  64.     rr:= ResourceReader.Create(resFile);
  65.     de:= IDictionaryEnumerator(rr.GetEnumerator);
  66.  
  67.     while IEnumerator(de).MoveNext do
  68.       resTbl.Add(de.Key,de.Value);
  69.  
  70.     rr.Close;
  71.     Result:= resTbl;
  72.   except
  73.     on Exception do
  74.       Result:= nil;
  75.   end;
  76. end;
  77.  
  78. procedure TMainForm.PaintHandler(Sender: TObject; pe: PaintEventArgs);
  79. begin
  80.   pe.Graphics.FillRectangle(SolidBrush.Create(Color.White), ClientRectangle);
  81.   pe.Graphics.DrawImage(SplashBitmap, 50, 50, 450, 350);
  82. end;
  83.  
  84. begin
  85.   Application.Run(TMainForm.Create(nil));
  86. end.
  87.